package com.aaa.service.impl;

import cn.hutool.core.date.DateUtil;
import com.aaa.entity.Playlist;
import com.aaa.mapper.PlaylistMapper;
import com.aaa.service.PlaylistService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

@Service
@Transactional
public class PlaylistServiceimpl implements PlaylistService {
    @Resource
    private PlaylistMapper playlistMapper;
    @Override
    public List<Playlist> playselectq(Integer lid) {
        return playlistMapper.playselectq(lid);
    }

    @Override
    public Playlist playselect(String ptitle) {
        return playlistMapper.playselect(ptitle);
    }

    @Override
    public Integer playinsert(Integer lid,Playlist playlist) {
        Integer lidpidinsert=null;
        playlist.setCreateDate(DateUtil.today());
        playlist.setPcolt(1);
        playlist.setState(0);
        Integer playinsert = playlistMapper.playinsert(playlist);
        if(playinsert==1){
            lidpidinsert = playlistMapper.lidpidinsert(lid, playlist.getPid());
        }
        return lidpidinsert;
    }

    @Override
    public Integer playlistsave(Playlist playlist) {
        return playlistMapper.playlistsave(playlist);
    }

    @Override
    public Integer pidmiddelete(Integer mid, Integer pid) {
        return playlistMapper.pidmiddelete(mid,pid);
    }

    @Override
    public Integer pidmidseleinsert(Integer mid, Integer pid) {
        Integer pidmid;
        Integer pidmidselect = playlistMapper.pidmidselect(mid, pid);
        if(pidmidselect>0){
            pidmid=0;
        }else{
            Integer pidmidinsert = playlistMapper.pidmidinsert(mid, pid);
            pidmid=pidmidinsert;
        }

        return pidmid;
    }

    @Override
    public Integer lidpidseleinsert(Integer lid,Integer mid) {
        Integer pidmid;
        Integer pidmidselect = playlistMapper.lidmidselect(lid, mid);
        if(pidmidselect>0){
            pidmid=0;
        }else{
            Integer pidmidinsert = playlistMapper.lidmidinsert(lid, mid);
            pidmid=pidmidinsert;
        }

        return pidmid;
    }


}
